package com.wisezone.java1902.d13_sort;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class StudentBean {
	private String name; // 姓名
	private int age; // 年龄
	private float score; // 成绩

	public StudentBean(String name, int age, float score) {
		this.name = name;
		this.age = age;
		this.score = score;
	}

	public String toString() {
		return name + "\t" + age + "\t" + score;
	}

	public static void main(String[] args) {
		StudentBean s1 = new StudentBean("小明", 23, 89);
		StudentBean s2 = new StudentBean("小丽", 22, 79);
		StudentBean s3 = new StudentBean("小强", 23, 99);
		StudentBean s4 = new StudentBean("小张", 23, 88);
		StudentBean s5 = new StudentBean("李四", 23, 90);

		StudentBean[] lists = { s1, s2, s3, s4, s5 };

		for (StudentBean student : lists) {
			System.out.println(student);
		}

		Arrays.sort(lists, new Comparator<StudentBean>() {
			public int compare(StudentBean o1, StudentBean o2) {
				float score = o1.score - o2.score;
				if (score > 0) {
					return 1;
				} else if (score < 0) {
					return -1;
				} else {
					return 0;
				}

			};
		});

		System.out.println("排序之后");

		for (StudentBean student : lists) {
			System.out.println(student);
		}
	}

}
